//
//  DetailsView.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/14.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "DetailsView.h"

#import "HAODEsingleton.h"


@interface DetailsView ()
{
    UIScrollView *mainScroll;
    UILabel *labelNumber;
    UILabel *labelDetail;
    UILabel *labelDetailContent;
    UIView *backView;
    UIView *viewBottom;
//    UIScrollView *imageScroll;
    
    HAODEsingleton*commdity;
}

@end

@implementation DetailsView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        mainScroll = [[UIScrollView alloc]initWithFrame:self.bounds];
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:mainScroll];
        
        commdity=[HAODEsingleton shared];
        
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 10, 40, 40)];
        _imageView.layer.masksToBounds = YES;
        _imageView.layer.cornerRadius = 40/2;
        _imageView.layer.borderColor = [UIColor whiteColor].CGColor;
        _imageView.layer.borderWidth = 0;
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        _imageView.userInteractionEnabled = YES;
        [mainScroll addSubview:_imageView];
        
  
        _buttonCheck = [[UIButton alloc]init];
         _buttonCheck.frame = CGRectMake(0, 0,40, 40);

        [_imageView addSubview:_buttonCheck];
    
        
        _labelName = [[UILabel alloc]initWithFrame:CGRectMake(_imageView.right+5,  10, ScreenWidth, 16)];
        _labelName.text = [NSString stringWithFormat:@"%@",@" 张学峰"];
        _labelName.font=[UIFont systemFontOfSize:16];
        _labelName.textColor = [UIColor blackColor];
        [mainScroll addSubview:_labelName];
        
        _labeltime = [[UILabel alloc]initWithFrame:CGRectMake(_imageView.right+5,  33, ScreenWidth, 15)];
        _labeltime.text = [NSString stringWithFormat:@"%@",@"广东深圳  2015-20-1"];
        _labeltime.textColor = [UIColor grayColor];
        _labeltime.font=[UIFont systemFontOfSize:13];
        [mainScroll addSubview:_labeltime];
        
        
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(15, 55, ScreenWidth-30, 0.35)];
        line.backgroundColor=labelColor;
        [mainScroll addSubview:line];
        
        
        _textV=[[UILabel alloc]initWithFrame:CGRectMake(15, 65, ScreenWidth-30, 40)];
        [mainScroll addSubview:_textV];
        //滚动图片
       
        
        _imageScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(15, _textV.bottom+5, ScreenWidth-40 , commdity.gaodu.intValue)];
        [mainScroll addSubview:_imageScroll];
        
        _imageScroll.contentSize = CGSizeMake(95 * _arrayImage.count, commdity.gaodu.intValue);
        _imageScroll.pagingEnabled = YES;
        _imageScroll.delegate = self;
        _imageScroll.showsHorizontalScrollIndicator = NO;
        
        
        UILabel*line11=[[UILabel alloc]initWithFrame:CGRectMake(15, _imageScroll.bottom+15, ScreenWidth-30, 0.35)];
        line11.backgroundColor=labelColor;
        [mainScroll addSubview:line11];
    
        UILabel *jiaoyijl = [[UILabel alloc]initWithFrame:CGRectMake(15, _imageScroll.bottom+30, 270, 17)];
        jiaoyijl.text = @"买家交易记录 ";
        jiaoyijl.font=[UIFont systemFontOfSize:16];
        jiaoyijl.textColor = [UIColor blackColor];
        [mainScroll addSubview:jiaoyijl];
 
        
        
        UILabel *xuqiuliang = [[UILabel alloc]initWithFrame:CGRectMake(15, jiaoyijl.bottom+20, 60, 17)];
        xuqiuliang.text = @"需求量";
        xuqiuliang.font=[UIFont systemFontOfSize:15];
        xuqiuliang.textColor = [UIColor grayColor];
        [mainScroll addSubview:xuqiuliang];
        _reqCount = [[UILabel alloc]initWithFrame:CGRectMake(xuqiuliang.right,  jiaoyijl.bottom+20, 45, 16)];
        _reqCount.text = [NSString stringWithFormat:@"%@",@"0"];
        _reqCount.font=[UIFont systemFontOfSize:15];
        _reqCount.textColor = [UIColor blackColor];
        [mainScroll addSubview:_reqCount];
        
        UILabel *chengjiaoliang = [[UILabel alloc]initWithFrame:CGRectMake(_reqCount.right, jiaoyijl.bottom+20, 60, 17)];
        chengjiaoliang.text = @"成交量";
        chengjiaoliang.font=[UIFont systemFontOfSize:15];
        chengjiaoliang.textColor = [UIColor grayColor];
        [mainScroll addSubview:chengjiaoliang];
        _reqSuccess = [[UILabel alloc]initWithFrame:CGRectMake(chengjiaoliang.right,  jiaoyijl.bottom+20, 45, 16)];
        _reqSuccess.font=[UIFont systemFontOfSize:15];
        _reqSuccess.textColor = [UIColor blackColor];
        [mainScroll addSubview:_reqSuccess];
        
        
        
        UILabel *chengjiaol = [[UILabel alloc]initWithFrame:CGRectMake(_reqSuccess.right, jiaoyijl.bottom+20, 60, 17)];
        chengjiaol.text = @"成交率";
        chengjiaol.font=[UIFont systemFontOfSize:15];
        chengjiaol.textColor = [UIColor grayColor];
        [mainScroll addSubview:chengjiaol];
        _reqSuccessP = [[UILabel alloc]initWithFrame:CGRectMake(chengjiaol.right,  jiaoyijl.bottom+20, 45, 16)];
        _reqSuccessP.font=[UIFont systemFontOfSize:15];
        _reqSuccessP.textColor = luseColor;
        [mainScroll addSubview:_reqSuccessP];
        
        
        UILabel*line1=[[UILabel alloc]initWithFrame:CGRectMake(15, chengjiaol.bottom+10, ScreenWidth-30, 0.35)];
        line1.backgroundColor=labelColor;
        [mainScroll addSubview:line1];
        
        
        
        UILabel *shuoming = [[UILabel alloc]initWithFrame:CGRectMake(15, chengjiaol.bottom+30, 260, 17)];
        shuoming.text = @"说明";
        shuoming.font=[UIFont systemFontOfSize:15];
        shuoming.textColor = [UIColor blackColor];
        [mainScroll addSubview:shuoming];
        
        
      

        _detail = [[UILabel alloc]initWithFrame:CGRectMake(15,  shuoming.bottom+10, ScreenWidth-40, 15)];
        _detail.font=[UIFont systemFontOfSize:15];
        _detail.numberOfLines=0;
        _detail.textColor = [UIColor grayColor];
        [mainScroll addSubview:_detail];
        
   
        mainScroll.contentSize = CGSizeMake(ScreenWidth, _detail.bottom);
        
    }
    return self;
}

- (void)setArrayImage:(NSArray *)arrayImage
{
    _arrayImage = arrayImage;
    for (int i=0; i<_arrayImage.count; i++) {
        UIImageView *imageVC = [[UIImageView alloc]init];
        [imageVC setImageWithURL:[NSURL URLWithString:_arrayImage[i]] placeholderImage:[UIImage imageNamed:@""]];
        imageVC.frame = CGRectMake(95*i, 0, 85, 85);
        [_imageScroll addSubview:imageVC];
    }
    _imageScroll.contentSize = CGSizeMake(95 * _arrayImage.count, 85);
    labelNumber.text = [NSString stringWithFormat:@"%d/%lu",1,(unsigned long)_arrayImage.count];
}

- (void)setContent:(NSString *)content
{
    NSString *string = [NSString stringWithFormat:@"%@",content];
    CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(ScreenWidth, 1000)];
    labelDetailContent.text = string;
    labelDetailContent.frame = CGRectMake(5, labelDetail.bottom+5, ScreenWidth - 10, size.height);
    _imageView.frame = CGRectMake(0, labelDetailContent.bottom + 5, ScreenWidth, 150);
    backView.frame = CGRectMake(5, _imageView.bottom + 10, ScreenWidth - 10, 70);
    viewBottom.frame = CGRectMake(0, backView.bottom + 10, ScreenWidth, 50);
    mainScroll.contentSize = CGSizeMake(ScreenWidth, viewBottom.bottom);
    _buttonTap.frame = _imageView.bounds;
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int contentOffsetX = scrollView.contentOffset.x;
    labelNumber.text = [NSString stringWithFormat:@"%d/%lu",contentOffsetX/200+1,(unsigned long)_arrayImage.count];
}



@end
